<?php
/**
 * List of news leads
 */
use Fox\Grid\FieldCat\Field\Renderer\Anchor;
use Shama\Contact\Status;
use Shama\Contact;
use Fox\Generator;
use Doctrine\DBAL\Connection;
use Fox\Dao\SqlFragment;
use Fox\Html\AnchorObject;

$finder = new Contact();
$types = array(Contact::TYPE_LEAD,Contact::TYPE_BASIC);
$leads = $finder->find(new SqlFragment("t.type IN (?) ",array($types),array(Connection::PARAM_STR_ARRAY)),
						array("udate" => "DESC"),
						array(Contact::$JOIN_PARTNERS_LEFT),
						null,
						true);

$grid = new Fox\Grid("gLeads",null,"Leads");
$grid->fieldcat(array('contactid','name1',array('contact_source','source'),'status','udate'))
		->switchToObjectMode();
$grid->fieldcat()->field('contactid')->noOutput();
$grid->fieldcat()->field('udate')
			->align('left')
			->displayTime();
$grid->setFieldAttr(array("name1",'source',"status"),"renderers",new Anchor(
		Generator::url('contacts','main',null,
					array('inLineId' => Generator::useAttribute('contactid'))
		)));
// Status
$grid->fieldcat()->setGenerators(array(
	'status' => Generator::useFunction(function($data){

		return $data->status()->label;
	}),
	'source' => Generator::useFunction(function($data){
		return $data->source()->label;
	})
));
$grid->initialize($leads,true);
echo $grid->display();